﻿function Transport(clb, room) {
    
    var _inst = this;

    var repeater = setTimeout(loop, 1000);

    var callback = clb;

    //Constructor
    (function () {

    })();

    _inst.SendMessage = function (text, name) {
        var resp = $.ajax({ type: 'POST', url: 'http://127.0.0.1:8080', data: { tp: 'send', r: room, message: text, nick: name }, async: false });

        return resp.responseText;
    }

    _inst.GetChatForRoom = function (room) {
        var resp = $.ajax({ type: 'POST', url: 'http://127.0.0.1:8080', data: { tp: 'get', r: room }, async: false });

        return resp.responseText;
    }

    _inst.Validate = function (passw) {
        var resp = $.ajax({ type: 'POST', url: 'http://127.0.0.1:8080', data: { tp: 'validate', password: passw }, async: false });

        return JSON.parse(resp.responseText).result;
    }

    function loop() {
        callback(_inst.GetChatForRoom(room));

        repeater = setTimeout(loop, 1000);
    }
}